package com.binhai.springboot.role.servie;

import com.binhai.springboot.role.bean.RoleBean;
import com.binhai.springboot.role.dao.RoleBeanDao;
import com.binhai.springboot.user.bean.UserBean;
import com.binhai.springboot.user.dao.UserBeanDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class RoleService {

    @Autowired
    private RoleBeanDao roleDao;
    /**
     * 查询所有数据
     * @param
     * @return
     */
    public List getAllData() {

        return roleDao.getAllData();
    }


    /**
     * 保存信息
     * @param bean
     * @return
     */
    public Map saveData(RoleBean bean) {
        Map re = new HashMap();
        try {
            //保存
          roleDao.insertSelective(bean);

            re.put("result", "success");
        } catch (Exception e) {
            re.put("result", "error");
            e.printStackTrace();
        }
        return re;
    }

    /**
     * 修改
     * @param bean
     * @return
     */

    public Map saveShouQuan(RoleBean bean) {
        Map re = new HashMap();
        try {
            //删除原有授权
            roleDao.deleteShouQuan(bean);
            roleDao.saveShouQuan(bean);
            re.put("result", "success");
        } catch (Exception e) {
            re.put("result", "error");
            e.printStackTrace();
        }
        return re;
    }

    public String getShouQuan( RoleBean bean) {
       return roleDao.getShouQuan(bean);
    }

    public List getAllRoleTreeData() {
        return  roleDao.getAllRoleTreeData();
    }

    public Map updateData(RoleBean bean) {
        Map re = new HashMap();
        try {
            roleDao.update(bean);

            re.put("result", "success");
        } catch (Exception e) {
            re.put("result", "error");
            e.printStackTrace();
        }
        return re;
    }

    public Map deleteData(RoleBean bean) {
        Map re = new HashMap();
        try {
            roleDao.delete(bean);

            re.put("result", "success");
        } catch (Exception e) {
            re.put("result", "error");
            e.printStackTrace();
        }
        return re;
    }

    public List selectData(String name) {
        return roleDao.select(name);
    }
}
